const nodemailer = require('nodemailer');

/**
 * 发件箱配置
 */
const transporter = nodemailer.createTransport({
  host: process.env.MAILER_HOST,
  port: process.env.MAILER_PORT,
  secure: process.env.MAILER_SECURE,
  auth: {
    user: process.env.MAILER_USER,
    pass: process.env.MAILER_PASS
  },
});

/**
 * 发送邮件
 * @param email
 * @param subject
 * @param html
 * @returns {Promise<void>}
 */
const sendMail = async (email, subject, html) => {
    await transporter.sendMail({
      from: process.env.MAILER_USER, // 发件箱
      to: email, // 发给谁
      subject, // 邮件的主题
      html, // 发送的邮件内容
    });
  }
  
  module.exports = sendMail;
  
